// pages/addPop/addPop.js
var t = getApp();
var other = require("../../utils/other");

Component({
  properties: {
    com_data: {
      type: Object,
      value: ""
    },
    show_com: {
      type: Number,
      value: "0"
    },
    title_index: {
      type: Number,
      value: 0
    },
    item_index: {
      type: Number,
      value: 0
    },
    pop_show: {
      type: Boolean,
      value: !0
    },
    sex_value: {
      type: Array,
      value: [0]
    },
    selectValue: {
      type: Number,
      value: 0
    },
  },
  data: {
    sex: '男',
    value: [0,0,0],
    item: ''
  },
  ready: function(){
    var that = this;
    
  },
  methods: {
    close_pop:function(){
      var pop_show = !this.properties.pop_show;
      this.triggerEvent('closePop', {pop_show})
    },
    // 选择性别
    picker_change_sex:function(e){
      var index = e.detail.value[0];
      this.setData({sex:this.properties.com_data[index]})
      this.triggerEvent('pickerChange', {index})
    },
    confirm_sex:function(){
      var that = this,sex=that.data.sex;
      this.triggerEvent('checksex', {sex})
      this.close_pop();
    },
    // 选择生日
    picker_change_time:function(e){
      var that = this,value = that.data.value,time = this.properties.com_data;
      var val = e.detail.value;
      if(val[1] != value[1]){
        var obj = other.getMonthDay(time[0][val[0]],time[1][val[1]])
        time[2] = obj;
        this.triggerEvent('changeTime', {time})
      }
      that.setData({value: val})
    },
    confirm_age:function(){
      var val = this.data.value,time=this.properties.com_data;
      var age = time[0][val[0]] +'-'+time[1][val[1]]+'-'+time[2][val[2]];
      this.triggerEvent('confirmTime', {age})
      this.close_pop();
    },
    // 选择在读年级
    check_inst:function(e){
      var that = this;
      var itm = e.currentTarget.dataset.item,index=e.currentTarget.dataset.index,idx=e.currentTarget.dataset.idx;
      var data={title_index:index,item_index:idx}
      this.triggerEvent('checkInst', {data})
      that.setData({item:itm})
    },
    confirm_inst:function(){
      var that = this;
      var item = that.data.item?that.data.item:'学前班'
      this.triggerEvent('confirmInst', {item})
      this.close_pop()
    },
  },
});